var
	path = require("path"),
	webpack = require("webpack"),
	CopyWebpackPlugin = require('copy-webpack-plugin'),
	ExtractTextPlugin = require("extract-text-webpack-plugin"),
	srcDirPath = __dirname + '/web/src/',
	jsDirPath = __dirname + "/web/src/js/",
	distDirPath = __dirname,
	libsDir = __dirname + '/web/src/js/libs';

module.exports = {
	// Configuration.
	// cache: false,
	context: srcDirPath,
	// 入口文件
	entry: {
		// Login build
		"js/site/login": jsDirPath + "site/login.js",
		// Doc build
		"js/doc/privacy": jsDirPath + "doc/privacy.js",
		// App build
		// Home
		"js/home/dashboard": jsDirPath + "home/dashboard.js",
		"js/home/userSettings": jsDirPath + "home/userSettings.js",
		// User
		"js/users/newUsers": jsDirPath + "users/newUsers.js",
		"js/users/userList": jsDirPath + "users/userList.js",
		"js/users/usersEdit": jsDirPath + "users/usersEdit.js",
		// Brand.
		"js/brand/brandList": jsDirPath + "brand/brandList.js",
		"js/brand/newBrand": jsDirPath + "brand/newBrand.js",
		// CampaignLabel.
		"js/label/labelList": jsDirPath + "label/labelList.js",
		"js/label/newLabel": jsDirPath + "label/newLabel.js",
		// Creative.
		"js/creative/creativeList": jsDirPath + "creative/creativeList.js",
		"js/creative/newCreative": jsDirPath + "creative/newCreative.js",
		"js/creative/newCpeCreative": jsDirPath + "creative/newCpeCreative.js",
		"js/creative/newCpeVideoCreative": jsDirPath + "creative/newCpeVideoCreative.js",
		"js/creative/creativeCpePreview": jsDirPath + "creative/creativeCpePreview.js",
		"js/creative/newVideoCreative": jsDirPath + "creative/newVideoCreative.js",
		"js/creative/newWebCreative": jsDirPath + "creative/newWebCreative.js",
		"js/creative/newAppCreative": jsDirPath + "creative/newAppCreative.js",
		"js/creative/newMobileVideoCreative": jsDirPath + "creative/newMobileVideoCreative.js",
		"js/creative/newCustomCreative": jsDirPath + "creative/newCustomCreative.js",
		"js/creative/creativeVideoPreview": jsDirPath + "creative/creativeVideoPreview.js",
		"js/creative/creativeMobileVideoPreview": jsDirPath + "creative/creativeMobileVideoPreview.js",
		// CreativeSync.
		"js/creativeSync/creativeSyncList": jsDirPath + "creativeSync/creativeSyncList.js",
		// Creativetemplate.
		"js/creativeTemplate/creativeTemplateList": jsDirPath + "creativeTemplate/creativeTemplateList.js",
		"js/creativeTemplate/newCreativeTemplate": jsDirPath + "creativeTemplate/newCreativeTemplate.js",
		// DaddyCall.
		"js/daddyCall/daddyCall": jsDirPath + "daddyCall/daddyCall.js",
		// Launch.
		"js/launch/launchList": jsDirPath + "launch/launchList.js",
		"js/launch/newLaunch": jsDirPath + "launch/newLaunch.js",
		// MediaList.
		"js/mediaList/blackWhiteList": jsDirPath + "mediaList/blackWhiteList.js",
		"js/mediaList/mediaList": jsDirPath + "mediaList/mediaList.js",
		"js/mediaList/newBlackWhite": jsDirPath + "mediaList/newBlackWhite.js",
		// PackList.
		"js/pack/packList": jsDirPath + "pack/packList.js",
		"js/pack/manageList": jsDirPath + "pack/manageList.js",
		"js/pack/newPack": jsDirPath + "pack/newPack.js",
		// "js/pack/editPack": jsDirPath + "pack/editPack.js",
		"js/app/appList": jsDirPath + "app/appList.js",
		"js/app/newApp": jsDirPath + "app/newApp.js",
		// PMP.
		"js/pmpList/pmpList": jsDirPath + "pmpList/pmpList.js",
		// Operate log.
		"js/operateLog/logList": jsDirPath + "operateLog/logList.js",
		// Package.
		"js/package/packageSync": jsDirPath + "package/packageSync.js",
		// Profit setting.
		"js/profitSetting/profitList": jsDirPath + "profitSetting/profitList.js",
		// Solution audit.
		"js/solutionAudit/solutionList": jsDirPath + "solutionAudit/solutionList.js",
		// Report.
		"js/report/reportList": jsDirPath + "report/reportList.js",
		// ResourceSync.
		"js/resourceSync/resourceSyncList": jsDirPath + "resourceSync/resourceSyncList.js",
		// Retarget.
		"js/retarget/newRetarget": jsDirPath + "retarget/newRetarget.js",
		"js/retarget/retargetList": jsDirPath + "retarget/retargetList.js",
		// Solution
		"js/solution/solutionList": jsDirPath + "solution/solutionList.js",
		"js/solution/newSolutionBasic": jsDirPath + "solution/newSolutionBasic.js",
		"js/solution/newSolutionResource": jsDirPath + "solution/newSolutionResource.js",
		"js/solution/newSolutionTarget": jsDirPath + "solution/newSolutionTarget.js",
		"js/solution/newSolutionBidding": jsDirPath + "solution/newSolutionBidding.js",
		"js/solution/newSolutionCreative": jsDirPath + "solution/newSolutionCreative.js",
		"js/solution/newPcSolutionBasic": jsDirPath + "solution/newPcSolutionBasic.js",
		"js/solution/newPcSolutionResource": jsDirPath + "solution/newPcSolutionResource.js",
		"js/solution/newPcSolutionTarget": jsDirPath + "solution/newPcSolutionTarget.js",
		"js/solution/newPcSolutionCreative": jsDirPath + "solution/newPcSolutionCreative.js",
	},
	// 输出配置
	output: {
		path: __dirname + '/web/built/wpbuilt/',
		publicPath: '/built/wpbuilt/',
		filename: "[name].js",
		chunkFilename: "[id]-[chunkhash:6].js"
		// chunkFilename: "[id].js"
	},
	externals: [{
  }],
	// 加载器配置
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract("style", "style!css")
      },
      {
        test: /\.scss$/,
        loader: "style!css!sass"
      },
      {
        test: /\.(png|jpg)/,
        loader: 'url-loader?limit=8192'
      }
    ],
    noParse: [
    ],
  },
  // 模块解析
	resolve: {
		root: [
			path.resolve('./web/src')
		],
		alias: {
			// Libs
			modernizr: "js/libs/modernizr-2.8.3.min",
			excanvas: "js/libs/excanvas.min",
			func: "js/libs/func",
			html5: "js/libs/html5",
			respond: "js/libs/respond.min",
			require: "js/libs/require",
			// Vendors
			jquery: "js/vendor/jquery-1.10.2.min",
			bootstrap: "js/vendor/bootstrap",
	    highcharts: "js/vendor/highcharts",
	    raphael: "js/vendor/raphael.min",
	    morris: "js/vendor/morris.min",
	    'jquery.cookie': "js/vendor/jquery.cookie",
	    spin: "js/vendor/spin",
	    datatables: "js/vendor/jquery.dataTables",
	    dataTables_bs: "js/vendor/dataTables.bootstrap",
	    dataTables_rsp: "js/vendor/dataTables.responsive",
	    dataTables_fh: "js/vendor/dataTables.fixedHeader",
	    messager: "js/vendor/messenger/messenger",
	    "bootstrap-dialog": "js/vendor/bootstrap-dialog",
	    "bootstrap-switch": "js/vendor/bootstrap-switch",
	    formAjax: "js/vendor/jquery.form",
	    select2: "js/vendor/select2",
	    jqueryUi: "js/vendor/jquery-ui",
	    moment: "js/vendor/moment",
	    daterangepicker: "js/vendor/daterangepicker",
	    flowplayer: "js/vendor/flowplayer/flowplayer",
	    "jquery.ui.widget": "js/vendor/jquery.ui.widget",
	    uploadFiles: "js/vendor/jquery.fileupload",
	    store: "js/vendor/store",
	    holder: "js/vendor/holder",
	    tree: "js/vendor/tree.jquery",
	    "amcharts": "js/vendor/amcharts",
	    "amcharts.serial": "js/vendor/serial",
			"amcharts.pie": "js/vendor/pie",
			jsTree: "js/vendor/jsTree",

	    // Module deps.
	    app: "js/app",
	    site: "js/site",
	    adspaceSize: "js/modules/adspaceSize",
	    backToTop: "js/modules/backToTop",
	    creativeList: "js/modules/creativeList",
	    dataTable: "js/modules/dataTable",
	    dataTableFilter: "js/modules/dataTableFilter",
	    dateRange: "js/modules/dateRange",
	    formChecky: "js/modules/formChecky",
	    formValidator: "js/modules/formValidator",
	    multiFormValidator: "js/modules/multiFormValidator",
	    func: "js/modules/func",
	    geoList: "js/modules/geoList",
	    listAsyncOp: "js/modules/listAsyncOp",
	    loading: "js/modules/loading",
	    notification: "js/modules/notification",
	    pageInit: "js/modules/pageInit",
	    params: "js/modules/params",
	    reportList: "js/modules/reportList",
	    siderMenu: "js/modules/siderMenu",
	    slidePanel: "js/modules/slidePanel",
	    tableColumnResize: "js/modules/tableColumnResize",
	    timeInterval: "js/modules/timeInterval",
	    topHeader: "js/modules/topHeader",
	    urlValidator: "js/modules/urlValidator",
	    adspaceListStore: "js/modules/adspaceListStore",
	    materialPreview: "js/modules/materialPreview",
	    languageMap: "js/modules/languageMap",
	    notice: "js/modules/notice"
		}
	},
	// 插件
	plugins: [
		new webpack.ProvidePlugin({
	    $: "jquery",
	    jQuery: "jquery",
	    "window.jQuery": "jquery"
		}),
		new webpack.optimize.CommonsChunkPlugin({
			name: [
				'js/site'
			],
			minChunks: Infinity
		}),
		new CopyWebpackPlugin([
			// Libs.
      { 
      	from: 'js/libs', 
      	to: 'js/libs' 
      },
      // CSS.
      { 
      	from: 'css', 
      	to: 'css' 
      },
      // Images.
      { 
      	from: 'img', 
      	to: 'img' 
      },
      // flowplay
      {
      	from: 'js/vendor/flowplayer',
      	to: 'js/vendor/flowplayer'
      }
	  ]),
	  new ExtractTextPlugin("[name].css", {
      allChunks: true
    })
	]
};